package com.zhy.mvc;

import com.zhy.service.PushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * 测试servlet3.0+异步方法
 * 异步任务的实现是通过控制器从另外一个线程返回一个DeferredResult， 这里的DeferredResult是从pushService中获得的
 * Created by zhy on 2017/5/9.
 */
@Controller
public class AysncController {

    @Autowired
    PushService pushService;

    /**
     * 返回给客户端DeferredResult
     */
    @RequestMapping("/defer")
    @ResponseBody
    public DeferredResult<String> deferredCall() {
        return pushService.getAsyncUpdate();
    }

}
